import java.util.ArrayList;
import java.util.Scanner;



public class predictionAlgorithmCorrelation {
	// Index order: DJIA(0), Nikkei(1), S&P(2), DAX(3), FTSE(4), CAC(5), SHANG(6), HANG(7)

	
	int i = 5; //needs to be inputted

	private static ArrayList<ArrayList<Double>> stockVals=new ArrayList<ArrayList<Double>>();	
	
	public predictionAlgorithmCorrelation(ReadingDataFromCSV data){
		stockVals=data.getStockData();

	}
	
	public static ArrayList<Double> getDay(int day){
		ArrayList<Double>temp=new ArrayList<Double>();
		for(ArrayList<Double>d:stockVals){
			temp.add(d.get(day));
		}
		return temp;
	}
	
	public static ArrayList<Double> getArray(int ind){
		ArrayList<Double>temp2=new ArrayList<Double>();
		temp2=stockVals.get(ind);
		return temp2;
	}

public void process(){
	System.out.print("Enter a stock date: ");
	Scanner scan = new Scanner(System.in);
	//int i = scan.nextInt();
	System.out.println();
	ArrayList<Double>temp3=new ArrayList<Double>();
	ArrayList<Double>difference=new ArrayList<Double>();
	int directionCounter=0;
	temp3=getArray(0);
	for(int i=0;i<115;i++){
			
		ArrayList<Double> today = getDay(i);
		ArrayList<Double> yester = getDay(i+1);
		double deltaAVG = 0;
		double deltaNASDAQ = (today.get(0)/yester.get(0))-1;
		double todayNASDAQ = today.get(0);
		System.out.println(i+ "'s Valu: "+todayNASDAQ);
		for(int a=4;a<today.size();a++){ //Equal Weight
			deltaAVG = deltaAVG+((today.get(a) / yester.get(a)) - 1);
		}
		deltaAVG=deltaAVG+((today.get(2) / yester.get(2)) - 1);
		deltaAVG = deltaAVG/6;
				
		//Weighted Average
		double deltaDJIA = ((today.get(1) / yester.get(1)) - 1);
		double deltaNIKKEI = ((today.get(2) / yester.get(2)) - 1);
		double deltaSP = ((today.get(3) / yester.get(3)) - 1);
		double deltaDAX = ((today.get(4) / yester.get(4)) - 1);
		double deltaFTSE = ((today.get(5) / yester.get(5)) - 1);
		double deltaCAC = ((today.get(6) / yester.get(6)) - 1);
		double deltaSHANG = ((today.get(7) / yester.get(7)) - 1);
		double deltaHANG = ((today.get(8) / yester.get(8)) - 1);
		
		// FOOLING AROUND
		/*todayNASDAQ=4161.46;
		//deltaDJIA=(###/16514.37)-1;
		deltaNIKKEI=(14546.27/14388.77)-1;
		//deltaSP=(###/1879.55)-1;
		deltaDAX=(9544.19/9600.09)-1;
		deltaFTSE=(6674.74/6681.76)-1;*/
		
		double unweighted = ((deltaCAC*1)+(deltaDAX*1)+(deltaFTSE*1)+(deltaHANG*1)+(deltaSHANG*1)+(deltaNIKKEI*1))/6;
		double weightedINTLDeltaAVG =  ((deltaCAC*6)+(deltaDAX*5)+(deltaFTSE*4)+(deltaHANG*3)+(deltaSHANG*2)+(deltaNIKKEI*1))/21;//((deltaDJIA*3)+(deltaNIKKEI*1)+(deltaSP*5)+(deltaDAX*4)+(deltaFTSE*2))/15;
		//weightedINTLDeltaAVG= ((deltaCAC*3)+(deltaDAX*2)+(deltaFTSE*1))/6;
		double tomorrowNASDAQ = yester.get(0) + (yester.get(0)*weightedINTLDeltaAVG);
		difference.add((tomorrowNASDAQ/todayNASDAQ)-1);
		
		if((weightedINTLDeltaAVG*deltaNASDAQ)>0){
			directionCounter++;
			//System.out.println(directionCounter);
		}
		
		double THRESHOLD = 0.005;
		
		System.out.println(i+ "'s Pred: "+tomorrowNASDAQ);
		System.out.println("Difference: "+((tomorrowNASDAQ/todayNASDAQ)-1));
		
		//System.out.println("Direction Validity: "+ deltaNASDAQ + " | " + weightedINTLDeltaAVG);
		System.out.println();
	}
	
	double error=0;
	for(int b=0;b<difference.size();b++){
		error = error+Math.abs(difference.get(b));
	}
	error=error/difference.size();
	System.out.println("% Error: "+ error);
	
	
	// Percent Error Value:
	//	Unweighted 	| .78254%
	//	Weighted 	| .78382% 	
	//
	// Absolute Error Value:
	// 	Unweighted	| $32.38
	//	Weighted	| $32.46
	// 
	
	
	//1-252
	/*System.out.println("NASDAQ Price: "+ today.get(0));
	System.out.println("NASDAQ Percent Change: "+deltaNASDAQ);
	System.out.println("Absolute Difference(EQ): " + Math.abs(deltaAVG-deltaNASDAQ));
	System.out.println("Absolute Difference(W): " + Math.abs(weightedDeltaAVG-deltaNASDAQ));
	
	/*System.out.println("NASDAQ Percent Change: "+deltaNASDAQ);
	System.out.println("Average Percent Change: "+deltaAVG);
	System.out.println("Absolute Difference: " + Math.abs(deltaAVG-deltaNASDAQ));
	System.out.println("Weighted Percent Change: " + weightedDeltaAVG);
	System.out.println("Absolute Difference: " + Math.abs(weightedDeltaAVG-deltaNASDAQ));
	/*if(deltaAVG>THRESHOLD)
		System.out.println("Sell NASDAQ");//sellStock();
	
	else if(deltaAVG<-THRESHOLD)
		System.out.println("Buy NASDAQ");//buyStock(); 
	else System.out.println("Do nothing");*/
	}

}

